package com.usian.controller;

import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemDesc;
import com.usian.service.ItemService;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/service")
public class ItemController {

    @Autowired
    private ItemService itemService;

    /**查询商品信息
     * 根据商品id
     * @param itemId
     * @return
     */

    @RequestMapping("/item/selectItemInfo")
    public TbItem selectItemInfo(Long itemId){
        return itemService.selectItemInfo(itemId);
    }

    @RequestMapping(value = "/item/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(Integer page,Integer rows){
        return itemService.selectTbItemAllByPage(page,rows);
    }

    /**
     * 商品的添加
     */
    @RequestMapping("/item/insertTbItem")
    public Integer insertTbItem(@RequestBody TbItem tbItem,@RequestParam String desc, @RequestParam String itemParams){
        return itemService.insertTbItem(tbItem,desc,itemParams);
    }

    /**
     * 根据商品 ID 查询商品，商品分类，商品描述，商品规格参数
     */

    @RequestMapping("/item/preUpdateItem")
    public Map<String, Object> preUpdateItem(Long itemId){
        return itemService.preUpdateItem(itemId);
    }

    /**
     * 商品的修改
     */
    @RequestMapping("/item/updateTbItem")
    public Integer updateTbItem(@RequestBody TbItem tbItem,@RequestParam String desc, @RequestParam String itemParams){
        return itemService.updateTbItem(tbItem,desc,itemParams);
    }

    /**
     * 商品的删除
     */
    @RequestMapping("/item/deleteItemById")
    public Integer deleteItemById(@RequestParam Long itemId){
        return itemService.deleteItemById(itemId);
    }

    /**
     * 商品类目的规格模板添加
     */
    @RequestMapping("/itemParam/insertItemParam")
    public Integer insertItemParam(@RequestParam Long itemCatId,@RequestParam String paramData){
        return itemService.insertItemParam(itemCatId,paramData);
    }

    /**
     * 查询所有商品规格模板
     */
    @RequestMapping("/itemParam/selectItemParamAll")
    public PageResult selectItemParamAll(Integer page,Integer rows){
        return itemService.selectItemParamAll(page,rows);
    }

    /**
     * 删除所有商品规格模板
     */
    @RequestMapping("/itemParam/deleteItemParamById")
    public Integer deleteItemParamById(Long id){
      return itemService.deleteItemParamById(id);
    }

    @RequestMapping("/detail/selectItemInfo")
    public TbItem selectItemInfoRedis(Long itemId){
        return  itemService.selectItemInfoRedis(itemId);
    }

    @RequestMapping("/detail/selectItemDescByItemId")
    public TbItemDesc selectItemDescByItemId(@RequestParam long itemId){
        return itemService.selectItemDescByItemId(itemId);
    }
}
